package com.itheima.userservice.rabbitmq;

import com.itheima.userservice.bean.MsgVo;
import com.itheima.userservice.mapper.MsgServiceMapper;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

@Component
public class RabbitConsumer {

    @Autowired
    private MsgServiceMapper msgServiceMapper;

    @RabbitListener(queues = "user_dead_queue")
    @RabbitHandler
    public void deadQueue(Message build, Channel channel) throws UnsupportedEncodingException {
        String s = new String(build.getBody(), "UTF-8");
        System.out.println("死信队列接受消息成功" + s);
        MsgVo msgVo = new MsgVo();
        msgVo.setStatus("3");
        msgVo.setId(1);
        msgServiceMapper.updateStatus(msgVo);
    }
}
